package com.easy.controller;

import com.easy.bean.OperationLog;
import com.easy.service.OperationLogService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/operation_log")
public class OperationLogController {
    
    @Autowired
    private OperationLogService operationLogService;
    
    /**
     * 查询所有操作日志
     */
    @GetMapping
    public Result findAll() {
        List<OperationLog> logs = operationLogService.findAll();
        return Result.success(logs);
    }
    
    /**
     * 根据ID查询操作日志
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        OperationLog log = operationLogService.findById(id);
        return Result.success(log);
    }
    
    /**
     * 分页查询操作日志
     */
    @GetMapping("/page")
    public Result page(Page page) {
        operationLogService.page(page);
        return Result.success(page);
    }
    
    /**
     * 删除操作日志
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        int result = operationLogService.del(id);
        if (result > 0) {
            return Result.success("删除成功");
        } else {
            return Result.fail(500, "删除失败");
        }
    }
}